#pragma once
using namespace std;
#include <string>
#include <iostream>
#include <stdarg.h>
#include <time.h>
#include <cstring>
#include <unistd.h>
// 日志等级
#define DEBUG 0
#define NORMAL 1
#define WARNING 2
#define ERROR 3
#define FATAL 4

const char *to_levelstr(int level)
{
    switch (level)
    {
    case DEBUG:
        return "DEBUG";
        break;
    case NORMAL:
        return "NORMAL";
        break;
    case WARNING:
        return "WARNING";
        break;
    case ERROR:
        return "ERROR";
        break;
    case FATAL:
        return "FATAL";
        break;
    default:
        return nullptr;
        break;
    }
}
void logMessage(int level, const char *format, ...)
{
    //[日志等级][时间戳/时间][pid][message]
    //[WARNING][2023-05-11 1:08:09][123][创建socket失败]

    // 暂定
    //  cout<<message<<endl;
#define NUM 1024
    char logprefix[NUM];
    snprintf(logprefix, sizeof(logprefix), "[%s][%ld][%d]", to_levelstr(level), (long int)time(nullptr), getpid());

    char logcontent[NUM];
    va_list arg;
    va_start(arg, format);

    vsnprintf(logcontent, sizeof(logcontent), format, arg);
    // 直接打印
     cout << logprefix << logcontent << endl;
    // 打印到文件
   
}